package entities;

/**
 * Entity Class for Users. A User has a username, a password and a member.
 * 
 * @author MK
 */
public class User {

	private String username;
	private String password;
	private Member member;

	private User() {
		super();
	}

	public User(String username, String password, Member member) {
		super();

		this.username = username;
		this.password = password;
		this.member = member;
	}

	public User(User user) {
		this(user.username, user.password, user.member);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((member == null) ? 0 : member.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (member == null) {
			if (other.member != null)
				return false;
		} else if (!member.equals(other.member))
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "User [member=" + member + ", usernname=" + username
				+ ", password=" + password + "]";
	}

	public int compareTo(User user) {
		if (this.username.compareTo(user.username) == 0
				&& this.member.compareTo(user.member) == 0) {
			return 0;
		} else {
			if (this.username.compareTo(user.username) != 0) {
				return this.username.compareTo(user.username);
			} else {
				return this.member.compareTo(user.member);
			}
		}
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}
}